package lovebomb.jfilesearch.engine.filetype;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

public class FileRead {

	private static FileRead fileRead = null;
	
	private FileRead(){
		
	}
	
	public static FileRead getInstance(){
		if( fileRead == null){
			fileRead = new FileRead();
		}
		return fileRead;
	}
	
	@SuppressWarnings("finally")
	public String readFile( String strFile){
		Path file = Paths.get(strFile);
		StringBuffer strNote = new StringBuffer();
		Charset charset = Charset.forName("EUC-KR");
		BufferedReader rr = null;
		FileReader fr = null;
		try {
			fr = new FileReader( strFile);
			rr = new BufferedReader( fr);			
			String buf = null;
			
			while((buf = rr.readLine()) != null ){
				strNote.append(buf);
			}
						
		} catch (Exception e) {
			e.printStackTrace();
		} finally{
			try {
				rr.close();
				fr.close();
			} catch (Exception e2) {
				e2.printStackTrace();
			}			
			return strNote.toString();
		}
		
		/*		
		Charset charset = Charset.forName("EUC-KR");
		try( BufferedReader reader = Files.newBufferedReader(file, charset)){
			String line = null;
			while( (line = reader.readLine()) != null){
				strNote.append( line);
			}
		} catch( Exception e){
			System.out.println( strFile);
			e.printStackTrace();
		} finally{
			return strNote.toString();
		}
*/
	
	
	}
	
}
